<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <p></p>

    <script>

        const oP = document.querySelector('p');

        // 再复刻一份数据的数据的时候，加入一些其他的行为

        const obj = {
            name: 'cc',
            age: 20
        };


        // 
        const obj2 = {};
        Object.defineProperty(obj2, 'name', {
            get() {
                return obj.name
            },
            set(v) {
                obj.name = v;
                // 当属性被修改的时候   这个set会自动调用
                oP.innerHTML = obj.name;
            }
        })

        Object.defineProperty(obj2, 'age', {
            get() {
                return obj.age
            },
            set(v) {
                obj.age = v;

            }
        })

        console.log(obj2);


        oP.innerHTML = obj2.name;



        document.onclick = function () {
            obj2.name = 'yy';
            console.log(777);
        }




    </script>

</body>

</html>